//
//  MyInfoController.m
//  EcmDoctor
//
//  Created by 张进 on 15/5/29.
//  Copyright (c) 2015年 张进. All rights reserved.
//

#import "MyInfoController.h"
#import "MyInfoCell.h"
#import "UIImageView+AFNetworking.h"
#import "DoctorIfo.h"
#import "PersonalInforationViewController.h"
#import "TreatmentsViewController.h"
#import "MyUnfinTaskViewController.h"
@interface MyInfoController ()<UITableViewDelegate,UITableViewDataSource>
{
    __weak IBOutlet UITableView *_infoTableView;
    __weak IBOutlet UILabel *_doctorName;
    __weak IBOutlet UILabel *_allordernum;
    NSArray *_dataAry;
    __weak IBOutlet UILabel *_doctorLevel;
    NSArray*_boolAry;
    NSArray *_pushAry;
}
@end

@implementation MyInfoController

@synthesize headerContainer,headerView;

- (void)viewDidLoad {
    [super viewDidLoad];

    _infoTableView.rowHeight=50;
   
    _dataAry=@[@"我的钱包",@"我的未完成任务",@"我的已完成任务",@"我的工作时间",@"我的资料",@"对我的评价",@"扫一扫",@"患者病历处方",@"治疗方案",@"帮助",@"设置",@"更多医生"];
    _boolAry=@[@"",@NO,@YES,@"",@"",@"",@"",@"",@"",@"",@"",@""];
    _pushAry=@[@"mywallet",@"myunfinishedtask",@"myunfinishedtask",@"worktime",@"myinfo",@"theEvaluationofme",@"Qrcode",@"patientrecods",@"teatmentslist",@"help",@"showMySetting",@"moredoctor"];
    //圆头像背景
    self.headerContainer.layer.cornerRadius = self.headerContainer.frame.size.width/2;
    self.headerContainer.clipsToBounds = YES;
    self.headerContainer.layer.borderWidth = 1.0f;
    self.headerContainer.layer.borderColor = [UIColor whiteColor].CGColor;
    self.headerContainer.backgroundColor = [UIColor clearColor];
    //圆头像
    self.headerView.layer.cornerRadius = self.headerView.frame.size.width/2;
    self.headerView.clipsToBounds = YES;
    //加载头像
    NSUserDefaults *doctorUser=[NSUserDefaults standardUserDefaults];
    [self.headerView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://ecm-user.oss-cn-beijing.aliyuncs.com/image/%@",[doctorUser objectForKey:APP_DOCTORICON_KEY]]] placeholderImage:[UIImage imageNamed:@"icon"]];
    _doctorName.text=[doctorUser objectForKey:APP_DOCTORNAME_KEY];
    _doctorLevel.text=[doctorUser objectForKey:APP_JOBPOSITION_KEY];
    //获取医生详细信息
    NSString *docId= [SSKeychain passwordForService:APP_SERVICE_NAME account:APP_DOCTORINFOID_KEY];
    [DoctorIfo getTheDoctorDetalInfoWith:docId success:^(DoctorIfo *doctor) {
        _allordernum.text=[NSString stringWithFormat:@"%@单",
                           [doctorUser objectForKey:APP_ALLORDENUM_KEY]];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
        
    }];
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if(indexPath.row==10)
//    {
//        [self performSegueWithIdentifier:@"showMySetting" sender:self];
//    }
//    if(indexPath.row==9)
//    {
//        [self performSegueWithIdentifier:@"help" sender:self];
//    }
//    if(indexPath.row==4)
//    {
//        [self performSegueWithIdentifier:@"myinfo" sender:self];
//    }
//    if(indexPath.row==11)
//    {
//        [self performSegueWithIdentifier:@"moredoctor" sender:self];
//    }
//    if(indexPath.row==3)
//    {
//        [self performSegueWithIdentifier:@"worktime" sender:self];
//    }
//    
//    if(indexPath.row==0)
//    {
//        [self performSegueWithIdentifier:@"mywallet" sender:self];
//    }
//    if(indexPath.row==5)
//    {
//        [self performSegueWithIdentifier:@"theEvaluationofme" sender:self];
//    }
//    if(indexPath.row==7)
//    {
//        [self performSegueWithIdentifier:@"patientrecods" sender:self];
//    }
//    if(indexPath.row==8)
//    {
//        [self performSegueWithIdentifier:@"teatmentslist" sender:self];
//    }
//    if(indexPath.row==1)
//    {
//      
//        [self performSegueWithIdentifier:@"myunfinishedtask" sender:_boolAry[indexPath.row-1]];
//    }
//    if(indexPath.row==2)
//    {
//        
//        [self performSegueWithIdentifier:@"myunfinishedtask" sender:_boolAry[indexPath.row-1]];
//   }
//    if(indexPath.row==6)
//    {
//        
//        [self performSegueWithIdentifier:@"Qrcode" sender:nil];
//    }

    [self performSegueWithIdentifier:_pushAry[indexPath.row] sender:_boolAry[indexPath.row]];


    self.navigationController.navigationBarHidden = NO;
//    self.navigationController.navigationBar.translucent = NO;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataAry.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell;
   
    MyInfoCell * myInfoCell = [tableView dequeueReusableCellWithIdentifier:@"ifoCell"forIndexPath:indexPath];
    
    if(indexPath.row%2)
        myInfoCell.backgroundColor=[UIColor whiteColor];
    else myInfoCell.backgroundColor=[UIColor colorWithRed:255/255.0 green:248/255.0 blue:238/255.0 alpha:1];
      myInfoCell.label.text=_dataAry[indexPath.row];
    
    if(indexPath.row==2||indexPath.row==1)
        myInfoCell.icon.image=[UIImage imageNamed:@"我的任务"];
    else myInfoCell.icon.image=[UIImage imageNamed:_dataAry[indexPath.row]];
    myInfoCell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell=myInfoCell;
    return cell;
}

- (void)viewDidAppear:(BOOL)animated{
    
  
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
    if ([segue.identifier isEqualToString:@"myinfo"]) {
        PersonalInforationViewController *piv;
         piv= segue.destinationViewController;
        piv.myInfo=1;
    }
    if ([segue.identifier isEqualToString:@"teatmentslist"]) {
        TreatmentsViewController* treatments = [segue destinationViewController];
    
        treatments.single=YES;
        treatments.i = 5;
    }
    if ([segue.identifier isEqualToString:@"myunfinishedtask"]) {
        MyUnfinTaskViewController* myUnfinTaskViewController = [segue destinationViewController];
        NSString * bl=sender;
   
        myUnfinTaskViewController.finish=bl.intValue;
       
    }
}

- (void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.hidden = YES;
    
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"hidden" object:nil userInfo:@{@"1":self}];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
        
        //需要注意的是self.isViewLoaded是必不可少的，其他方式访问视图会导致它加载 ，在WWDC视频也忽视这一点。
        
        if (self.isViewLoaded && !self.view.window)// 是否是正在使用的视图
        {
            // Add code to preserve data stored in the views that might be
            // needed later.
            
            // Add code to clean up other strong references to the view in
            // the view hierarchy.
            self.view = nil;// 目的是再次进入时能够重新加载调用viewDidLoad函数。
        }
        
    }
    // Dispose of any resources that can be recreated.
}


-(void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
//    self.navigationController.navigationBar.translucent = NO;
    
}



@end
